package com.jivam.lottery.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import com.jivam.lottery.util.Constants;
/**
 * 一个公式面板的基类,可以声明多个公式左边项目提供对比
 * @author Jivam
 */
public class KeyFormula implements Serializable{

	private static final long serialVersionUID = -8971188471615926176L;
	private String key;//公式面板的KEY
	private List<Expression> expressions;//公式左边列表
	private List<Formula> formulas;//公式右边列表
	
	private LinkedList<int[]> datas;//对应每期的每个公式的值的集合
	
	public KeyFormula(String key) {
		super();
		this.key = key;
		this.expressions = new ArrayList<Expression>();
		this.formulas = new ArrayList<Formula>();
		this.datas = new LinkedList<int[]>();
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public List<Expression> getExpressions() {
		return expressions;
	}
	
	public void addExpression(String expression) {
		addExpression(new Expression(expression));
	}
	
	public void addExpression(Expression expressions) {
		this.expressions.add(expressions);
	}

	public void setExpressions(List<Expression> expressions) {
		this.expressions = expressions;
	}

	public List<Formula> getFormulas() {
		return formulas;
	}

	public void addFormula(String expression) {
		addFormula(new Formula(expression));
	}
	
	public void addFormula(Formula formula) {
		this.formulas.add(formula);
	}

	public LinkedList<int[]> getDatas() {
		return datas;
	}
	
	public int[] getLastData() {
		if(datas.size() == 0)
			return null;
		return datas.getLast();
	}

	public void addDatas(int[] data) {
		if(datas.size() == Constants.MAX_FORMULA_DATA_SIZE){//
			datas.removeFirst();
		}
		this.datas.addLast(data);
	}

	@Override
	public String toString() {
		return "Key="+key+", F="+formulas;
	}
	
}
